<?php

namespace App\Model;

use Hyperf\DbConnection\Model\Model;

/**
 *  IP黑名单
 */
class IpBlacklist extends Model
{
    protected $table = 'ip_blacklist';
    protected $fillable = ['client_ip', 'flag'];

    static function checkIpBlack($clientIp = '')
    {
        if (!$clientIp) return false;
        $where = ['client_ip' => $clientIp, 'flag' => 1];
        return self::where($where)->count() > 0;
    }

    static function addIp($ip)
    {
        return self::updateOrCreate(['client_ip' => $ip], ['flag' => 1]);
    }
}
